package com.sec.key.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sec.base.utils.AjaxJson;
import com.sec.key.entity.Key;
import com.sec.key.service.KeyService;

@RestController
@RequestMapping(value = "/key")
@CrossOrigin
public class KeyController {

	@Autowired
	private KeyService keyService;

	/**
	 * 获取分页数据
	 * 
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "findKeyListByPage", method = RequestMethod.POST)
	public AjaxJson findKeyListByPage(HttpServletRequest request, int pageNumber, int pageSize) {
		return keyService.findKeyListByPage(request, pageNumber, pageSize);
	}

	/**
	 * 密码新增或更新
	 * 
	 * @param user
	 * @return
	 */
	@RequestMapping(value = "saveOrUpdate", method = RequestMethod.POST)
	public AjaxJson saveOrUpdate(HttpServletRequest request, Key key) {
		return keyService.saveOrUpdate(request, key);
	}

	/**
	 * 查询密码信息
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "getKeyInfo", method = RequestMethod.POST)
	public AjaxJson getKeyInfo(String id) {
		return keyService.getKeyInfo(id);
	}

	/**
	 * 删除密码
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "deleteKey", method = RequestMethod.POST)
	public AjaxJson deleteKey(String id) {
		return keyService.deleteKey(id);
	}

	@RequestMapping(value = "findAllKeyByLoginUser", method = RequestMethod.POST)
	public AjaxJson findAllKeyByLoginUser(HttpServletRequest request) {
		return keyService.findAllKeyByLoginUser(request);
	}
}
